let result = (|| {
let args: Vec<_> = try!(env::args_os()
.map(|s| {
- s.into_string().map_err(|s| CargoError::from(format!("invalid unicode in argument: {:?}", s)))
+ s.into_string().map_err(|s| {
+ CargoError::from(format!("invalid unicode in argument: {:?}", s))
+ })
})
.collect());
let rest = &args;
handle_cause(err, shell);
}
-fn handle_cause<E, EKind>(cargo_err: E, shell: &mut MultiShell) -> bool where E: ChainedError<ErrorKind=EKind> + 'static {
+fn handle_cause<E, EKind>(cargo_err: E, shell: &mut MultiShell) -> bool
+ where E: ChainedError<ErrorKind=EKind> + 'static {
fn print(error: String, shell: &mut MultiShell) {
let _ = shell.err().say("\nCaused by:", BLACK);
let _ = shell.err().say(format!(" {}", error), BLACK);
//Print remaining errors until one marked as Internal appears
for err in cargo_err.iter().skip(1) {
let err = unsafe { extend_lifetime(err) };
- if let Some(&CargoError(CargoErrorKind::Internal(..), ..)) = err.downcast_ref::<CargoError>() {
+ if let Some(&CargoError(CargoErrorKind::Internal(..), ..)) =
+ err.downcast_ref::<CargoError>() {
return false;
}
&mut |out_line| { state.stdout(out_line); Ok(()) },
&mut |err_line| { state.stderr(err_line); Ok(()) },
).map_err(|e| {
- let desc = e.description().to_string();
- CargoError::with_chain(e, format!("failed to run custom build command for `{}`\n{}",
- pkg_name, desc))
+ CargoError::from(
+ format!("failed to run custom build command for `{}`\n{}",
+ pkg_name, e.description()))
+
})?;
paths::write(&output_file, &output.stdout)?;
use core::source::{Source, SourceId};
use core::GitReference;
use core::{Package, PackageId, Summary, Registry, Dependency};
-use util::{CargoResult, Config};
+use util::Config;
+use util::errors::{CargoError, CargoResult};
use util::hex::short_hash;
use sources::PathSource;
use sources::git::utils::{GitRemote, GitRevision};
trace!("updating git source `{:?}`", self.remote);
let repo = self.remote.checkout(&db_path, self.config)?;
- let rev = repo.rev_for(&self.reference)?;
+ let rev = repo.rev_for(&self.reference).map_err(CargoError::to_internal)?;
(repo, rev)
} else {
(self.remote.db_at(&db_path)?, actual_rev.unwrap())
info!("update submodules for: {:?}", repo.workdir().unwrap());
for mut child in repo.submodules()?.into_iter() {
- update_submodule(repo, &mut child, cargo_config).chain_err(|| {
- format!("failed to update submodule `{}`",
- child.name().unwrap_or(""))
+ update_submodule(repo, &mut child, cargo_config)
+ .map_err(CargoError::to_internal)
+ .chain_err(|| {
+ format!("failed to update submodule `{}`",
+ child.name().unwrap_or(""))
})?;
}
Ok(())
// In the case of an authentication failure (where we tried something) then
// we try to give a more helpful error message about precisely what we
// tried.
- res.chain_err(|| {
+ res.map_err(CargoError::from).map_err(|e| e.to_internal()).chain_err(|| {
let mut msg = "failed to authenticate when downloading \
repository".to_string();
if !ssh_agent_attempts.is_empty() {
impl CargoError {
pub fn to_internal(self) -> Self {
+ //This is actually bad, because it loses the cause information for foreign_link
CargoError(CargoErrorKind::Internal(self.description().to_string()), self.1)
}
&CargoErrorKind::TomlDe(_) => true,
&CargoErrorKind::Curl(_) => true,
&CargoErrorKind::HttpNot200(..) => true,
+ &CargoErrorKind::ProcessErrorKind(_) => true,
&CargoErrorKind::CrateRegistry(_) |
&CargoErrorKind::ParseSemver(_) |
&CargoErrorKind::Semver(_) |
&CargoErrorKind::Parse(_) |
&CargoErrorKind::Git(_) |
&CargoErrorKind::Internal(_) |
- &CargoErrorKind::ProcessErrorKind(_) |
&CargoErrorKind::CargoTestErrorKind(_) => false
}
}
if exit.success() {
Ok(())
} else {
- Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
- self.debug_string()),
- Some(&exit), None)).into())
+ Err(CargoErrorKind::ProcessErrorKind(process_error(
+ &format!("process didn't exit successfully: `{}`", self.debug_string()),
+ Some(&exit), None)).into())
}
}
let mut command = self.build_command();
let error = command.exec();
Err(CargoError::with_chain(error,
- CargoErrorKind::ProcessErrorKind(
- process_error(&format!("could not execute process `{}`",
- self.debug_string()), None, None))))
+ CargoErrorKind::ProcessErrorKind(process_error(
+ &format!("could not execute process `{}`", self.debug_string()), None, None))))
}
#[cfg(windows)]
if output.status.success() {
Ok(output)
} else {
- Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
- self.debug_string()),
- Some(&output.status), Some(&output))).into())
+ Err(CargoErrorKind::ProcessErrorKind(process_error(
+ &format!("process didn't exit successfully: `{}`", self.debug_string()),
+ Some(&output.status), Some(&output))).into())
}
}
status: status,
};
if !output.status.success() {
- Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
- self.debug_string()),
- Some(&output.status), Some(&output))).into())
+ Err(CargoErrorKind::ProcessErrorKind(process_error(
+ &format!("process didn't exit successfully: `{}`", self.debug_string()),
+ Some(&output.status), Some(&output))).into())
} else if let Some(e) = callback_error {
Err(CargoError::with_chain(e,
- CargoErrorKind::ProcessErrorKind(
- process_error(&format!("failed to parse process output: `{}`",
- self.debug_string()), Some(&output.status), Some(&output)))))
+ CargoErrorKind::ProcessErrorKind(process_error(
+ &format!("failed to parse process output: `{}`", self.debug_string()),
+ Some(&output.status), Some(&output)))))
} else {
Ok(output)
}
match res {
Ok(out) => self.match_output(&out),
- Err(CargoError(CargoErrorKind::ProcessErrorKind(ProcessError { output: Some(ref out), .. }), ..)) => {
+ Err(CargoError(CargoErrorKind::ProcessErrorKind(
+ ProcessError { output: Some(ref out), .. }), ..)) => {
self.match_output(out)
}
Err(e) => {